/////////////////////////////////////////////////////////////////////////////
// Name:        ax_fallbacks.cpp
// Purpose:     Fallbacks classes
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#include "wx/wx.h"

#include "ax/ax_utils.h"

#include "ax_resource/ax_fallbacks.h"
#include "ax_resource/ax_resource_library.h"

/*
 * AxFileResource implementation.
 * A resource can represent a tool, document, file, web site, etc.
 */

IMPLEMENT_DYNAMIC_CLASS(AxFileResource, AxResource)

AxFileResource::~AxFileResource()
{
}

void AxFileResource::Init()
{
}

/*
 * AxFallbackModule implementation.
 * A module for dealing with audio files
 */

IMPLEMENT_DYNAMIC_CLASS(AxFallbackModule, AxModule)

bool AxFallbackModule::sm_fallbacksEnabled = true;

// Constructor.
AxFallbackModule::AxFallbackModule()
{
    SetPriority(-1000);
}

// Called on IDE startup, before the main window has been created.
bool AxFallbackModule::OnInit()
{
    return true;
}

// Called on application startup, after the main window has been created.
bool AxFallbackModule::OnInitUI()
{
    return true;
}

// Called just before program termination, but only if OnInit()
// succeeded.
void AxFallbackModule::OnExit()
{
}

// Read config settings
bool AxFallbackModule::LoadConfig(wxConfigBase& config)
{
    wxUnusedVar(config);
    return true;
}

// Write config settings
bool AxFallbackModule::SaveConfig(wxConfigBase& config)
{
    wxUnusedVar(config);
    return true;
}

// Is this file supported?
bool AxFallbackModule::IsFileSupported(const wxString& filename)
{
    wxString ext(AxFileUtilities::GetExtension(filename).Lower());
    if (GetFallbacksEnabled())
        return (GetLibrary()->GetSettings().GetSupportedFiles().IsEnabled(ext));
    else
        return false;
}

// Load the file into a new AxResource
AxResource* AxFallbackModule::LoadResource(const wxString& filename)
{
    AxFileResource* resource = new AxFileResource;
    resource->SetProperty(axPROPERTY_TITLE, wxFileNameFromPath(filename));
    resource->SetFilename(filename);
    
    return resource;
}

// Aggregate any files that belong together and add to library. Return false if you don't
// aggregate any files.
bool AxFallbackModule::AggregateFiles(AxResourceLibrary* WXUNUSED(library), wxArrayString& WXUNUSED(files), bool WXUNUSED(checkIfFileLoaded))
{
    return false;
}

// Create an activator for the resource, for creating views and further menu items.
AxActivator* AxFallbackModule::CreateActivator(AxResourceLibrary* WXUNUSED(library), AxResource* WXUNUSED(resource))
{
    // TODO
    return NULL;
}
